 
layui.define(['form','laydate','xmSelect'], function(exports){
	var $ = layui.$
    ,setter = layui.setter


	//如果确认到达时间  和 确认结束时间不为空
	if ($("[name='confirmArrivalTime']").val() !== "" && $("[name='confirmOverTime']").val() !== "") {

		//根据时间寻找空闲月台
		layui.admin.req({
			url: setter.host + '/reservation/receiveManager/freePlatformByTime'
			, type: 'post'
			, contentType: "application/x-www-form-urlencoded"
			, data: {
				startTime: $("#confirmArrivalTime").val(),
				keepTime: Number($("#durationTime").val())
			}
			, done: function (res) {
				//请求成功后
				if (res.code == 0) {
					$(`[id=platform] option`).remove()
					for (let r of res.data) {
						if (r.sure === 1) {
							$(`[id=platform]`).append(`<option value="${r.platformNumber}">${r.platformCode}</option>`)
						} else {
							$(`[id=platform]`).append(`<option disabled="disabled" value="${r.platformNumber}">${r.platformCode}</option>`)
						}
					}
					layui.form.render('select');
				} else {
					layer.msg(res.msg);
				}
			}
		})

		//根据时间寻找空闲收货员
		layui.admin.req({
			url: setter.host + '/reservation/receiveManager/freeReceiverByTime'
			, type: 'post'
			, contentType: "application/x-www-form-urlencoded"
			, data: {
				startTime: $("#confirmArrivalTime").val(),
				keepTime: Number($("#durationTime").val())
			}
			, done: function (res) {
				$(`[id =receiver] option`).remove()
				if (res.code == 0) {
					for (let r of res.data) {
						if (r.sure === 1) {
							$(`[id=receiver]`).append(`<option value="${r.receiverNumber}">${r.receiverName}</option>`)
						} else {
							$(`[id=receiver]`).append(`<option disabled="disabled" value="${r.receiverNumber}">${r.receiverName}</option>`)
						}
					}
					layui.form.render('select');
				} else {
					layer.msg(res.msg);
				}
			}
		})

	}

  //对外暴露的接口
    exports('reallocation', {});
});